import { GSprite } from "../../../../com/mui/controls/GSprite";
import { GModuleEvent } from "../../mvc/GModuleEvent";
import { SuitConfig } from "../../resource/SuitConfig";
import { ESpiritEquipSuitType } from "../../../../Message/Public/ESpiritEquipSuitType";
import { SuitInfo } from "../../resource/info/SuitInfo";
import { LookupPlayerData } from "../player/LookupPlayerData";
import { Cache } from "../../cache/Cache";
import { ObjCreate } from "../common/ObjCreate";
import { ResFileConst } from "../../resource/ResFileConst";
import { Language } from "../../../../extend/language/Language";
import { GlobalStyle } from "../../../common/global/GlobalStyle";
import { SuitAttributePanel } from "./SuitAttributePanel";
import { SpiritEquipHDPlayer } from "./SpiritEquipHDPlayer";
import { LoaderHelp } from "../../../common/display/LoaderHelp";
import { SpiritEquipGrayItem } from "./SpiritEquipGrayItem";
import { GButton } from "../../../../com/mui/controls/GButton";
import { Dispatcher } from "../../../mvc/core/Dispatcher";
import { DataEvent } from "../../events/DataEvent";
import { EventName } from "../../mvc/EventName";
import { GlobalClass } from "../../../../com/mui/core/GlobalClass";
import { ImagesConst } from "../../resource/ImagesConst";
import { ToolTipInfo } from "../../model/ToolTipInfo";
import { HTMLUtil } from "../../../../com/gengine/utils/HTMLUtil";
import { NormalTooltip } from "../common/tooltip/NormalTooltip";
import { GLoadedButton } from "../../../../com/mui/controls/GLoadedButton";
import { GTextFiled } from "../../../../com/mui/controls/GTextFiled";
import { SSuitSetPartsInfo } from "../../../../Message/Public/SSuitSetPartsInfo";
type int = number;
//class PlayerSpiritEquipPanel
    
    export  class PlayerSpiritEquipPanel extends GSprite
    {
        constructor()
        {
            super();
            this._suitCode = [1400, 1401, 1402, 1403, 1404];
            this._suitInfoDict = new Map<any, any> /* flash.utils.Dictionary */();
            this._graySpriteArray = [];
            this.init();
            return;
        }

        public set mode(arg1: string)
        {
            this._mode = arg1;
            return;
        }

        public updateSpiritEquipInfo(): void
        {
            this.updateSuit();
            return;
        }

        /* internal  */updateEnable(arg1: int): void
        {
            var loc1=null;
            var loc2=0;
            while (loc2 < this._graySpriteArray.length) 
            {
                loc1 = this._graySpriteArray[loc2];
                loc1.mode = this._mode;
                if (loc2 < arg1) 
                {
                    loc1.isGray = false;
                }
                else 
                {
                    loc1.isGray = true;
                }
                ++loc2;
            }
            return;
        }

        /* internal  */updateSuit(): void
        {
            var loc1=null;
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                if (this._mode == GModuleEvent.Mode_Other) 
                {
                    loc1 = SuitConfig.instance.getInfoByCode(ESpiritEquipSuitType._ESpiritEquipSuitDragonPurple);
                    this._suitInfo = new SuitInfo(loc1, LookupPlayerData.lookupData.miniPlayer.career, true);
                    this._suitNumDict = Cache.instance.spiritEquip.getSuitNumDictBySMapSuitSetPartsInfo(LookupPlayerData.lookupData.mapSpiritEquipSuitSetInfo);
                    this._eatDragonNum = this._suitNumDict[1];
                    this._skillsArray = Cache.instance.spiritEquip.getSkillsArrayBySuitNumDict(this._suitNumDict);
                    this._enableIndex = Cache.instance.spiritEquip.getEnableIndexBySuitNumDict(this._suitNumDict);
                    this._strengthenBtn.enabled = false;
                    this._eatBtn.enabled = false;
                }
            }
            else 
            {
                this._suitInfo = Cache.instance.spiritEquip.enEnableDragonSuitInfo;
                this._suitNumDict = Cache.instance.spiritEquip.suitNumDict;
                this._eatDragonNum = Cache.instance.spiritEquip.enEatedDragonNum;
                this._skillsArray = Cache.instance.spiritEquip.getSkillsArray();
                this._enableIndex = Cache.instance.spiritEquip.getEnableIndex();
                this._strengthenBtn.enabled = true;
                this._eatBtn.enabled = true;
            }
            if (this._dragonNumTxt) 
            {
                this._dragonNumTxt.text = "( " + this._eatDragonNum + "/" + this._suitInfo.num + " )";
            }
            this._suitAttPanel.updateSuitAtt(this._suitInfo);
            this._suitAttPanel.updateActiveNum(this._eatDragonNum);
            this._suitAttPanel.updateSkillList(this._skillsArray);
            this.updateEnable(this._enableIndex);
            return;
        }

        /* internal  */init(): void
        {
            var loc1=null;
            this._imgBg = ObjCreate.createBitmap(null, 4, 0, this);
            this._targetBtn = ObjCreate.createGLoadedButton(ResFileConst.SpiritEquipTarget, 10, 10, 44, 44, this);
            this._targetBtn.addEventListener(flash.events.MouseEvent.ROLL_OVER, this.onTargetBtnOverHandler);
            this._strengthenBtn = ObjCreate.createGButton(Language.getString(36630), 104, 257, 70, 24, this, "ButtonYellow");
            this._eatBtn = ObjCreate.createGButton(Language.getString(36635), 225, 257, 70, 24, this, "ButtonYellow");
            this._eatBtn.name = "spiritEquipEatBtn";
            this._strengthenBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._eatBtn.addEventListener(flash.events.MouseEvent.CLICK, this.onBtnClickHandler);
            this._tipsBmp = ObjCreate.createBitmap(null, 10, 302, this);
            this._dragonNumTxt = ObjCreate.createGTextField("", 145, 302, 150, 20, this, GlobalStyle.textFormat6);
            this._suitAttPanel = new SuitAttributePanel();
            this._suitAttPanel.x = 10;
            this._suitAttPanel.y = 330;
            addChild(this._suitAttPanel);
            this._hdPlayer = new SpiritEquipHDPlayer();
            this._hdPlayer.x = 210;
            this._hdPlayer.y = 220;
            addChild(this._hdPlayer);
            this._hdBitmap = new Object /* flash.display.Bitmap */();
            this._hdBitmap.x = 130;
            this._hdBitmap.y = 115;
            this.addChild(this._hdBitmap);
            LoaderHelp.addResCallBack(ResFileConst.SpiritEquip, this.onResLoaded);
            var loc2=[{"x": 84, "y": 185}, {"x": 100, "y": 87}, {"x": 205, "y": 35}, {"x": 310, "y": 87}, {"x": 328, "y": 185}];
            var loc3=0;
            while (loc3 < loc2.length) 
            {
                loc1 = new SpiritEquipGrayItem(loc3 + 1);
                loc1.x = loc2[loc3].x;
                loc1.y = loc2[loc3].y;
                this.addChild(loc1);
                this._graySpriteArray.push(loc1);
                ++loc3;
            }
            return;
        }

        /* internal  */onTargetBtnOverHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            this._targetBtn.toolTipData = this.getToolTipData();
            return;
        }

        /* internal  */onBtnClickHandler(arg1: Object /* flash.events.MouseEvent */): void
        {
            var loc1=(arg1.target as GButton).name;
            var loc2=1;
            if (loc1 == "spiritEquipEatBtn") 
            {
                loc2 = 0;
            }
            Dispatcher.dispatchEvent(new DataEvent(EventName.SpiritEquipWindowOpen, loc2));
            return;
        }

        /* internal  */onResLoaded(): void
        {
            this._imgBg.bitmapData = GlobalClass.getBitmapData(ImagesConst.SpiritEquipBg);
            this._tipsBmp.bitmapData = GlobalClass.getBitmapData(ImagesConst.SpiritEquipTips);
            this._hdBitmap.bitmapData = GlobalClass.getBitmapData(ImagesConst.PlayerSpiritEquipHd);
            return;
        }

        /* internal  */getToolTipData(): ToolTipInfo
        {
            var loc2=0;
            var loc7=null;
            var loc10=0;
            var loc11=null;
            var loc12=0;
            var loc1=[];
            if (this._mode != GModuleEvent.Mode_Self) 
            {
                if (this._mode == GModuleEvent.Mode_Other) 
                {
                    loc2 = Cache.instance.spiritEquip.getEatedSuitNumBySuitNumDict(this._suitNumDict);
                }
            }
            else 
            {
                loc2 = Cache.instance.spiritEquip.getEatedSuitNum();
            }
            var loc3=loc2 != 0 ? loc2 : 1;
            var loc4=Cache.instance.spiritEquip.suitInfoDict[loc3];
            var loc5=this._suitNumDict[loc3];
            var loc6=Language.getStringByParam(36636, loc4.name, loc5, loc4.num);
            var loc8;
            if (loc8 = loc5 >= loc4.num) 
            {
                loc6 = loc6 + HTMLUtil.addColor(Language.getString(30035) + "\n\n", "#00ff00");
                loc7 = "#f0ea3f";
            }
            else 
            {
                loc6 = loc6 + HTMLUtil.addColor(Language.getString(30036) + "\n\n", "#ff0000");
                loc7 = "#7c7c7c";
            }
            loc6 = loc6 + (Cache.instance.spiritEquip.getAddSuitAttrStr(loc2, false, this._suitNumDict) + "\n\n");
            loc1.push(loc6);
            var loc9=loc2 < 5;
            if (loc8 && loc9) 
            {
                loc10 = loc3 + 1;
                loc11 = Cache.instance.spiritEquip.suitInfoDict[loc10];
                loc12 = this._suitNumDict[loc10];
                loc6 = (loc6 = (loc6 = Language.getString(61089) + "\n") + Language.getStringByParam(36637, loc11.name, loc12, loc11.num)) + (Cache.instance.spiritEquip.getAddSuitAttrStr(loc10, false, this._suitNumDict) + "\n");
                loc1.push(loc6);
            }
            if (!this._toolTipInfo) 
            {
                this._toolTipInfo = new ToolTipInfo(NormalTooltip.ToolTipRenderType_Separate, loc1);
            }
            this._toolTipInfo.tooltipData = loc1;
            return this._toolTipInfo;
        }

        /* internal */ /* var */_imgBg: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_hdBitmap: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_targetBtn: GLoadedButton;

        /* internal */ /* var */_strengthenBtn: GButton;

        /* internal */ /* var */_eatBtn: GButton;

        /* internal */ /* var */_tipsBmp: Object /* flash.display.Bitmap */;

        /* internal */ /* var */_dragonNumTxt: GTextFiled;

        /* internal */ /* var */_hdPlayer: SpiritEquipHDPlayer;

        /* internal */ /* var */_suitAttPanel: SuitAttributePanel;

        /* internal */ /* var */_suitCode: Array<any>;

        /* internal */ /* var */_suitInfoDict: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_sSuitSetPartsInfo: SSuitSetPartsInfo;

        /* internal */ /* var */_mode: string="自己";

        /* internal */ /* var */_graySpriteArray: Array<any>;

        /* internal */ /* var */_suitInfo: SuitInfo;

        /* internal */ /* var */_suitNumDict: Map<any, any> /* flash.utils.Dictionary */;

        /* internal */ /* var */_eatDragonNum: int;

        /* internal */ /* var */_skillsArray: Array<any>;

        /* internal */ /* var */_enableIndex: int;

        /* internal */ /* var */_toolTipInfo: ToolTipInfo;
    }
